<?php 
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view');

class modSketchupSearchHelper {

	var $db = null;
	var $filter_country = null;
	var $search = null;

	/**
	 * modSketchupSearchHelper::__construct()
	 *
	 * Class constructor
	 *
	 * @return void
	 */
	function __construct() {
		global $option;

		$app =& JFactory::getApplication();

		$this->db =& JFactory::getDBO();
		$this->search = $app->getUserStateFromRequest( "$option.search", 'search', '', 'string' );
		$this->filter_country = $app->getUserStateFromRequest( "$option.filter_country", 'filter_country', '', 'string' );		
	}

	function getCountryDropdown() {
		$query = "SELECT Distinct country as value FROM #__sketchup WHERE published = '1' ORDER BY country ASC";
		$this->db->setQuery($query);
		$options = $this->db->loadObjectList();

		if ( $this->db->getErrorNum() ) {
			JError::raiseWarning( 200, $this->db->getErrorMsg() );
		}

		// make the select do something
		$js = 'onchange="document.getElementById(\'sketchupSearch\').submit();"';

		array_unshift($options, JHTML::_('select.option', ' select ', $options ));

		$value = $this->filter_country;

		if ($this->search != '') {
			$value = '';
		}

		$country_select = JHTML::_('select.genericlist',  $options, 'filter_country', 'class="input" size="1"'.$js, 'value', 'value', $value);

		return $country_select;
	}

	function getSearch()
	{
		return $this->search;
	}

}//the end
 
?>


		